import matplotlib.pyplot as plt
import numpy as np

# add_subplot():在画布添加绘图子区域
# rows:绘图区域所占行数
# cols:绘图区域所占列数
# index:绘图子区域的索引
def mat_subplot2():
    x = np.linspace(-1, 1, 100)
    y1 = np.sin(x)
    y2 = np.cos(x)
    y3 = np.tan(x)
    y4 = x ** 2
    y5 = np.arcsin(x)
    y6 = x

    fig, axs = plt.subplots(2, 3, figsize=(12, 8))
    axs[0, 0].plot(x, y1, label='sin(x)')
    axs[0, 0].legend()

    axs[0, 1].plot(x, y2, label='cos(x)')
    axs[0, 1].legend()

    axs[0, 2].plot(x, y3, label='tan(x)')
    axs[0, 2].legend()

    axs[1, 0].plot(x, y4, label='y=x^2')
    axs[1, 0].legend()

    axs[1, 1].plot(x, y5, label='y=arcsin(x)')
    axs[1, 1].legend()

    axs[1, 2].plot(x, y6, label='y=x')
    axs[1, 2].legend()

    plt.show()


if __name__ == '__main__':
    mat_subplot2()